<?php
/**
 * IMPORTANT: Do not use this controller for writing your own code!!
 * @return 
 */
class Corrector extends Controller {

	function Corrector() {
	    parent::Controller();
	    //$this->load->model('model_data'); 
	    $this->load->model('model_corrector');
	    if (!$this->usersession->userLoggedIn()) {
		$aResponse = array ("error"=>true,"description"=>"Sesiunea a expirat","type"=>"nosession");
		die(json_encode($aResponse));
	    }
	}
	//functia de aducere a obiectelor
	function bringObject() {
	    $table = $this->input->post('table');
	    $where['name'] = $this->input->post('name');
	    
	    $dir = $this->input->post("dir");
	    $sort = $this->input->post("sort");
	    
	    echo json_encode($this->model_corrector->bringObject($table, $s_limit, $e_limit, $sort, $dir, $where));
	}
	//functie de editare a numelui unui obiect sau subobiect	
	function editObject() {
		echo json_encode($this->model_corrector->editObject($_POST));
	}
	function transfer() {
		echo json_encode($this->model_corrector->transfer($_POST));
	}
	//functie de stergere obiecte si subobiecte
	function delete() {
		echo json_encode($this->model_corrector->delete($_POST));
	}
	/**
	 * Functie de export
	 */
	function export() {
		
	    $sTable=$this->uri->segment(3);
	    $where['name']=$this->uri->segment(4);
    
	    $result=$this->model_corrector->bringObject($sTable, $s_limit, $e_limit, $sort, $dir, $where);	
	    
	    
	    header("Content-type: application/vnd.ms-excel;charset=utf-8");
	    header("Expires: 0");
	    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
	    header("Content-disposition:  attachment; filename=raport.xls");
	    $this->load->library('xmlexcel');
	    $newexcel=new Xmlexcel;
	       
	    $newexcel->write_header();
	    $newexcel->write_document_properties('MTP');
	    $newexcel->write_styles();
	       
	    $newexcel->start_worksheet();
	    $newexcel->write_row('		
		<Column ss:Width="400"/>
		<Column ss:Width="400"/>');
		   
	   		    
	    $newexcel->write_row('
		<Row>		   
		 <Cell ss:StyleID="headerStyle"><Data ss:Type="String">OBIECT</Data></Cell>
		 <Cell ss:StyleID="headerStyle"><Data ss:Type="String">SUBOBIECT</Data></Cell>    	   
		</Row>'); 
		  
		  
		  
	    foreach($result['DS_OBJECT'] as $key=>$row) {
	       
		if($row["level"]=="0") {
		    $sObj = $row["obj"];
		    $sSubobj = "";				
		} else {
		    $sObj = "";
		    $sSubobj = $row["obj"];
		}
	       
	       
	       $newexcel->write_row('<Row>   				      
		    <Cell ss:StyleID="defaultComp"><Data ss:Type="String">'.strTitle(str_replace($litere_er,$litere_sol,$sObj)).'</Data></Cell>
		    <Cell ss:StyleID="defaultComp"><Data ss:Type="String">'.strTitle(str_replace($litere_er,$litere_sol,$sSubobj)).'</Data></Cell>	
		    </Row>');
	    } 	   
	   
		$newexcel->end_worksheet(); 
		$newexcel->write_footer();
		print $newexcel->output();
		exit;    
  
	}

}